package com.yyfax.ph.home.todolist;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * P: 获取待办数目
 * Created by ying_he on 2017/11/4.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class ToDoListSizePresenter extends Presenter<ToDoListSizeModel, ToDoListSizePresenter.View> {
	private static final String TAG = ToDoListSizePresenter.class.getSimpleName();
	private ToDoListSizePresenter.View mView;

	public static class Generator implements PresenterFactory<ToDoListSizePresenter> {
		@Override
		public ToDoListSizePresenter create() {
			return new ToDoListSizePresenter();
		}
	}

	public interface View extends IView {
		void getToDoListSizeSuccess(String size);
	}

	@Override
	public void attach(ToDoListSizePresenter.View view) {
		mView = view;
		mModel = new ToDoListSizeModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public void getToDoListSize() {
		execute(null, FUNCTIONAL_CODE, false);
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void getToDoListSizeResult(ToDoListSizeModel.ToDoListSizeResult result) {
		if (isResponseSuccess(result)) {
			mView.getToDoListSizeSuccess(result.getContent().count);
		}
	}
}
